#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <chrono>
#include <sstream>

#include <opencv2/opencv.hpp>
#include <Eigen/Dense>

#include "BYTETracker.h"
#include "opencv_utils.h"
#include "colormap_parser.h"



int main(){
    // Initialize a ByteTracker object
    BYTETracker tracker(0.23, 30, 0.8, 30); 
    std::cout << cv::getBuildInformation() << std::endl;

    // Initialize VideoCapture
    // cv::VideoCapture cap("/mnt/nfs_share/rk_c++/test/hbb.mp4");
    cv::VideoCapture cap("rtsp://192.168.10.105/av_stream/0");

    // std::string pipeline = "filesrc location=/mnt/nfs_share/rk_c++/test/hbb.mp4 ! "
    //                    "qtdemux ! h264parse ! mppvideodec ! "
    //                    "videoconvert ! video/x-raw, format=(string)BGR ! appsink sync=false";

    // // 使用 OpenCV 打开视频流
    // cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);

    if (!cap.isOpened()) {
        std::cout << "Error: Could not open the video file." << std::endl;
        return -1;
    }   
    double frame_width = cap.get(cv::CAP_PROP_FRAME_WIDTH);   // Get the width of the video
    double frame_height = cap.get(cv::CAP_PROP_FRAME_HEIGHT); // Get the height of the video
    double fps = cap.get(cv::CAP_PROP_FPS);  // Get the FPS of the input video
    double total_frames = cap.get(cv::CAP_PROP_FRAME_COUNT);
    std::cout << std::endl;
    std::cout << "Video Info:" << std::endl;
    std::cout << "Frame Width: " << frame_width << std::endl;
    std::cout << "Frame Height: " << frame_height << std::endl;
    std::cout << "FPS: " << fps << std::endl;
    std::cout << "Frames: " << total_frames << std::endl;
    cv::Mat frame;
    while (true) {
        // 读取下一帧
        if (!cap.read(frame)) {
            std::cerr << "Video has ended or failed" << std::endl;
            break;
        }
        if (frame.empty()) {
            break;
        }

        // Prepare an input image for inference
        cv::Mat resized_img;
        // 指定大小调整
        cv::Size size(1080, 1080);  // 新的尺寸，宽300像素，高200像素
        cv::resize(frame, resized_img, size);
        // Create a window
        cv::namedWindow("Image Display", cv::WINDOW_AUTOSIZE);

        // Display the image in the window
        cv::imshow("Image Display", resized_img);

        // Wait for a key press indefinitely
        cv::waitKey(10);
    }




    return 0;
}